package org.jeecg.modules.wmhb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.constant.FillRuleConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.SelectTreeModel;
import org.jeecg.common.util.FillRuleUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.wmhb.entity.*;
import org.jeecg.modules.wmhb.mapper.WmItemMapper;
import org.jeecg.modules.wmhb.service.IWmItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.constant.UserConstant;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 物料产品表
 * @Author: jeecg-boot
 * @Date:   2024-08-31
 * @Version: V1.0
 */
@Service
public class WmItemServiceImpl extends ServiceImpl<WmItemMapper, WmItem> implements IWmItemService {

    @Override
    public String checkItemCodeUnique(WmItem wmItem) {
        WmItem item = baseMapper.checkItemCodeUnique(wmItem);
        String itemId = wmItem.getId() == null ? "" : wmItem.getId();
        if(item != null && !itemId.equals(item.getId())){
            return UserConstant.NOT_UNIQUE;
        }else{
            return UserConstant.UNIQUE;
        }
    }

    @Override
    public String checkItemNameUnique(WmItem wmItem) {
        WmItem item = baseMapper.checkItemNameUnique(wmItem);
        String itemId = wmItem.getId() == null ? "" : wmItem.getId();
        if(item != null && !itemId.equals(item.getId())){
            return UserConstant.NOT_UNIQUE;
        }else{
            return UserConstant.UNIQUE;
        }
    }

    @Override
    public WmItem selectByCode(String code){
        LambdaQueryWrapper<WmItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WmItem::getCode, code).last("LIMIT 1");
        return getOne(queryWrapper);
    };

    @Override
    public WmItem selectByName(String name){
        LambdaQueryWrapper<WmItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WmItem::getName, name).last("LIMIT 1");
        return getOne(queryWrapper);
    };

    @Override
    public List<WmItem> projectList(){
        return baseMapper.projectList();
    };
}
